﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WF_TheTourManagement
{
    public partial class MainProgram : Form
    {

        string testString;
        public MainProgram()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        DataTable dt1;
        DataTable dt2;

        
        private void MainProgram_Load(object sender, EventArgs e)
        {
            Location _location = new Location();
            dt1= _location.getLocationsList();
            dt2 = _location.getLocationsList();
            //dt2.Clear();
            //testString = _location.getLocationsList()[0].ToString();
            rebindListbox(lbx1, dt1);
            rebindListbox(lbx2, dt2);





        }

        private void test_Click(object sender, EventArgs e)
        {
            DataRowView rowView = lbx1.SelectedItem as DataRowView;
            if (null == rowView)
            {
                return;
            }
            dt1.Rows.Remove(rowView.Row);
            rebindListbox(lbx1);
            //MessageBox.Show(lbx1.SelectedIndex.ToString());

        }

        private void rebindListbox(ListBox lbx, DataTable dt)
        {
            lbx.DataSource = null;
            lbx.DataSource = dt;

            lbx1.DisplayMember = "LocationName";
            lbx1.ValueMember = "LocationId";
        }

        private void rebindListbox(ListBox lbx)
        {
            lbx.DataSource = null;
            lbx.DataSource = dt1;

            lbx1.DisplayMember = "LocationName";
            lbx1.ValueMember = "LocationId";
        }

        private void btnPassRight_Click(object sender, EventArgs e)
        {
            DataRowView rowView = lbx1.SelectedItem as DataRowView;
            if (null == rowView)
            {
                MessageBox.Show("Please choose a Location");
                return;
            }

            DataRowView row2 = rowView;


            dt2.ImportRow(rowView.Row);
            dt1.Rows.Remove(rowView.Row);
            //dt2.ImportRow(rowView.Row);
            rebindListbox(lbx1,dt1);
            rebindListbox(lbx2,dt2);
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        

    }
}
